package com.dwxt.community.admin.service;

import com.dwxt.common.base.YesOrNo;
import com.dwxt.community.dao.CustomerProblemMapper;
import com.dwxt.community.entity.CustomerProblem;
import com.dwxt.community.entity.vo.CustomerProblemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceAdmin {
    @Autowired
    private CustomerProblemMapper customerProblemMapper;

    public List<CustomerProblemVO> selectCustomerList(String username) {
        return customerProblemMapper.selectCustomerList(username);
    }

    public void commitReply(Integer id, String reply) {
        //查询最早的问题
        CustomerProblem problem = customerProblemMapper.selectByPrimaryKey(id);

        //插入回复信息
        CustomerProblem customerProblem = new CustomerProblem();
        customerProblem.setIsProblem(YesOrNo.NO);
        customerProblem.setIsHandle(YesOrNo.YES);
        customerProblem.setConversationId(problem.getConversationId());
        customerProblem.setUserId(problem.getUserId());
        customerProblem.setProblem(reply);
        customerProblemMapper.insertSelective(customerProblem);

        //更改最早的问题，标记位已处理
        if(problem.getIsHandle()==YesOrNo.NO){
            problem.setIsHandle(YesOrNo.YES);
            customerProblemMapper.updateByPrimaryKeySelective(problem);
        }
    }
}
